package middleSearch;

/**
 * @description: 描述
 * @author: Mr.Hu
 * @create: 2022/3/19 11:22
 **/
public class SearchInsertPosition {
    public static void main(String[] args) {
        int[] nums = {1,3,5,7};
        int target =0;
        SearchInsertPosition searchInsertPosition = new SearchInsertPosition();
        int result = searchInsertPosition.searchInsert(nums, target);
        System.out.println(result);
    }
    public static int searchInsert(int[] nums, int target) {
            int n = nums.length;
            int left = 0, right = n - 1, ans = n;
            while (left <= right) {
                int mid = ((right - left) >> 1) + left;
                if (target <= nums[mid]) {
                    ans = mid;
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
            return ans;
        }

    }

